package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.UserShoppingCartService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
public class UserShoppingCartController {

    @Autowired
    UserShoppingCartService userShoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result SaveShoppingCart(@RequestBody ShoppingCartDTO dto) {
        userShoppingCartService.SaveShoppingCart(dto);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list() {
        List<ShoppingCart> list = userShoppingCartService.list();
        return Result.success(list);
    }
    @DeleteMapping("clean")
    public Result cleanShoppingCart(){
        userShoppingCartService.cleanShoppingCart();
        return Result.success();
    }
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO dto){
        userShoppingCartService.sub(dto);
        return Result.success();

    }


}
